package com.zyh.day03

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object CacheTest {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName("ct")
      .setMaster("local[*]")
    val sc = new SparkContext(conf)
    val rdd1: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4, 5))

    val rdd2: RDD[String] = rdd1.map(item => item + "-" + System.currentTimeMillis())

    rdd2.cache()
    println(s"System.currentTimeMillis() = ${System.currentTimeMillis()}")
    Thread.sleep(2000)
    //第一次遍历
    rdd2.foreach(println)
    //第二次遍历
    Thread.sleep(3000)
    rdd2.foreach(println)

    rdd2.unpersist()
    //第三次遍历
    Thread.sleep(3000)
    rdd2.foreach(println)

    sc.stop()
  }
}
